package com.mingjieli.excel.form;

import java.util.List;

/**
 * 数据表格模型，对应需要到处的sheet中的业务子表，业务子表有可能有多个
 * @author mingjie
 * @since 2020-05-18
 */
class GridModel {
	private DIRECT           direct;
	private TitleModel       rowTitle;
	private TitleModel       columnTitle;
	private List<TitleModel> itemTitleList;

	public DIRECT getDirect() {
		return direct;
	}

	public void setDirect(DIRECT direct) {
		this.direct = direct;
	}

	public TitleModel getRowTitle() {
		return rowTitle;
	}

	public void setRowTitle(TitleModel rowTitle) {
		this.rowTitle = rowTitle;
	}

	public TitleModel getColumnTitle() {
		return columnTitle;
	}

	public void setColumnTitle(TitleModel columnTitle) {
		this.columnTitle = columnTitle;
	}

	public List<TitleModel> getItemTitleList() {
		return itemTitleList;
	}

	public void setItemTitleList(List<TitleModel> itemTitleList) {
		this.itemTitleList = itemTitleList;
	}

	/**
	 * 业务子表的数据行的开始
	 * @return 开始行号
	 */
	public int getBodyStartRowNum() {
		if (direct == DIRECT.HORIZONTAL) {
			TitleModel titleModel = itemTitleList.get(0);
			return titleModel.getStartRowNum() + titleModel.getHeight();
		}
		return -1;
	}

	/**
	 * 业务子表的数据开始列号
	 * @return 开始列号
	 */
	public int getBodyStartColumnNum() {
		if (direct == DIRECT.VERTICAL) {
			TitleModel titleModel = itemTitleList.get(0);
			return titleModel.getStartColumnNum() + titleModel.getWidth();
		}
		return -1;
	}

	/**
	 * 业务子表数据的高度
	 * @return body高度
	 */
	public int getBodyHeight() {
		if (direct == DIRECT.HORIZONTAL) {
			int columnTitleEndRowNum = columnTitle.getStartRowNum() + columnTitle.getHeight();
			return columnTitleEndRowNum - getBodyStartRowNum();
		}
		return -1;
	}

	/**
	 * 业务子表数据的宽度
	 * @return body宽度
	 */
	public int getBodyWidth() {
		if (direct == DIRECT.VERTICAL) {
			int rowTitleEndColumnNum = rowTitle.getStartColumnNum() + rowTitle.getWidth();
			return rowTitleEndColumnNum - getBodyStartColumnNum();
		}
		return -1;
	}

	public enum DIRECT {
		HORIZONTAL, //水平表，根据表头判断
		VERTICAL //竖直表，根据表头判断
	}
}
